import socket

from protobuf.example_pb2 import Example, Level

example = Example()
example.index = 1
example.channelId = "1"
example.timestamp = "2021-12-27"
example.level.append(Level.NONE)
example.level.append(Level.DEBUG)
example.header = "{'xxx':22}"
example.body = "{'xxx':11}"

xx = example.SerializeToString()
print(example)
print(xx)

s = socket.socket()  # 创建 socket 对象
host = "127.0.0.1"
port = 8999

s.connect((host, port))
s.send(xx)
s.recv(1024)
s.close()
